<?php /**/ ?><?php
 // drupal_add_css(drupal_get_path('theme', 'name_of_your_theme') .'/image_gallery.css');

 
//dprint_r($galleries);
//dprint_r($images); 

  $content = '';
  if (count($galleries)) {
		$content .= '<ul class="galleries">';
  $count = 0;
  foreach ($galleries as $gallery) {

  
  if ($count == 2) {$class = "clearleft"; $count = 0;}
  else {$class="";};
      $content .= '<li class="gallery-album '.$class.'">';
      if ($gallery->count) {
        $content .= l(image_display($gallery->latest, 'albumthumb'), 'image/tid/'. $gallery->tid, array('html' => TRUE, 'attributes' => array('class' => 'featuredimage')));
      }
	  $content .= "<div class='gallery-description'>\n";
	  
	  $changed = $gallery->latest;
	  $changed = $changed->changed;

	  $datecompare = time();
	  $datecompare = $datecompare-(60*60*24*60);
	  $olddate = mktime(10, 0, 0, 1, 25, 2009);
	//  print 'New: '.$changed.' and old '. $olddate;
	  if (($changed > $datecompare) && ($changed > $olddate)) {$content .="<div class=\"newflag\">New</div>";}
	  
      $content .= "<h3>". l($gallery->name, 'image/tid/'. $gallery->tid) ."</h3>\n";
      $content .= '<div class="description">'. check_markup($gallery->description) ."</div>\n";
      //$content .= '<p class="count">'. format_plural($gallery->count, 'There is 1 image in this gallery', 'There are @count images in this gallery') ."</p>\n";
      if ($gallery->latest->changed) {
        $content .= '<p class="last">('. format_plural($gallery->count,"1 image","@count images").') '. t('%date', array('%date' => format_date($gallery->latest->changed, 'custom', 'm-d-Y'))) ."</p>\n";
      }
	  $content .= "</div>\n";
	  $content .= "<div class=\"clearboth\"></div>\n";
      $content .= "</li>\n";
	  $count++;
    }
    
  }
	$content .= "</ul>\n";
	$content .= '<div class="clearboth"></div>'."\n";

  if (!empty($images)) {
    $content .= '<ul class="images">';
    foreach ($images as $image) {
	  $content .= '<li class="gallery-display">';
	  $content .= l(image_display($image, 'thumbnail'), 'node/'. $image->nid, array('html' => TRUE, 'attributes' => array('class' => 'thumbnailimage')));
      $content .= '</li>';
    }
    $content .= "</ul>\n";
	$content .= '<div class="clearboth"></div>'."\n";
  }

  if ($pager = theme('pager', NULL, variable_get('image_images_per_page', 6), 0)) {
    $content .= $pager;
  }

  if (count($images) + count($galleries) == 0) {
      $content .= '<p class="count">'. format_plural(0, 'There is 1 image in this gallery', 'There are @count images in this gallery') ."</p>\n";
  }

 // print_r($content);
  print $content;
?>